import { Dayjs } from '../dayjs/index.js';

/**
 * 
 * @desc 创建一个 value 的深拷贝。
 * @param {value(*)}  要拷贝的值
 * @return {(*)} 拷贝后的值
 */
function cloneDeep(obj) {
	if (obj === null || typeof obj !== 'object' || obj instanceof Dayjs) {
		return obj;
	}

	if (Array.isArray(obj)) {
		let copy = [];
		for (let i = 0; i < obj.length; i++) {
			copy[i] = cloneDeep(obj[i]);
		}
		return copy;
	}

	if (typeof obj === 'object') {
		let copy = {};
		for (let key in obj) {
			if (obj.hasOwnProperty(key)) {
				copy[key] = cloneDeep(obj[key]);
			}
		}
		return copy;
	}
}

export {
	cloneDeep
};